home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / misc / emu / iecutil.lha / IECEDir.p < prev    next >
Encoding:
Text File  |  1997-08-19  |  7.0 KB  |  264 lines

  1. program IECEDir;
  2.  
  3. {$path "inc/"}
  4. {$incl "lib/iec.lib"}
  5. {$incl "lib/intuition.lib"}
  6. {$incl "lib/graphics.lib"}
  7. {$incl "intuition/screens.h"}
  8. {$incl "graphics/view.h"}
  9. {$incl "libraries/diskfont.h"}
  10. {$incl "exec/io.h"}
  11. {$incl "exec/ports.h"}
  12.  
  13. type colors = array[0..3] of integer;
  14.      grafText = record
  15.                   h,
  16.                   v,
  17.                   len: integer;
  18.                   txt: string[40]
  19.                 end;
  20.  
  21. var revVid, done: Boolean;
  22.     ch: char;
  23.     lenSep, drive,
  24.     low, high, rowNo, size, devyce, errCode, status, i: integer;
  25.     ptrScr: ^Screen;
  26.     ptrWin: ^Window;
  27.     ptrVP: ^ViewPort;
  28.     ptrRP: ^RastPort;
  29.     ptrMP: ^MsgPort;
  30.     ptrIOR: ^IOStdReq;
  31.     blues: colors;
  32.     sep: string[3];
  33.     countStr: string[8];
  34.     nameC, nameS: string[32];
  35.     font64: TextAttr;
  36.     huh: ^TextFont;
  37.     newS: NewScreen;
  38.     lines: array[0..7] of grafText;
  39.  
  40. procedure showLine(lineK: integer);
  41.   begin
  42.     Move(ptrRP, lines[lineK].h * 8, lines[lineK].v * 8 + {6}7);
  43.     GrafxText(ptrRP, ^lines[lineK].txt, lines[lineK].len)
  44.   end;
  45.  
  46. function keybdRd: char;
  47.   var c: char;
  48.       status: long;
  49.   begin
  50.     ptrIOR^.IO_COMMAND := CMD_READ;
  51.     ptrIOR^.IO_DATA := ^c;
  52.     ptrIOR^.IO_LENGTH := 1;
  53.     status := DoIO(ptrIOR);
  54.     keybdRd := c
  55.   end;
  56.  
  57. begin
  58.   blues[0] := $077E;
  59.   blues[1] := $0EEE;
  60.   blues[2] := $077E;
  61.   blues[3] := $011C;
  62.   lines[0].h := 4;
  63.   lines[0].v := 1;
  64.   lines[0].txt := '**** COMMODORE 64 BASIC V2 ****';
  65.   lines[1].h := 1;
  66.   lines[1].v := 3;
  67.   lines[1].txt := '64K RAM SYSTEM  38911 BASIC BYTES FREE';
  68.   lines[2].h := 0;
  69.   lines[2].v := 5;
  70.   lines[2].txt := 'READY.';
  71.   lines[3].h := 0;
  72.   lines[3].v := 6;
  73.   lines[3].txt := 'LOAD"$';
  74.   lines[4].h := 0;
  75.   lines[4].v := 8;
  76.   lines[4].txt := 'SEARCHING FOR $';
  77.   lines[5].h := 0;
  78.   lines[5].v := 9;
  79.   lines[5].txt := 'LOADING';
  80.   lines[6].h := 0;
  81.   lines[6].v := 10;
  82.   lines[6].txt := 'READY.';
  83.   lines[7].h := 0;
  84.   lines[7].v := 11;
  85.   lines[7].txt := 'LIST';
  86.   for i := 0 to 7
  87.     do lines[i].len := length(lines[i].txt);
  88.   OpenLib(IntBase, 'intuition.library', 0);
  89.   OpenLib(DiskFontBase, 'diskfont.library', 0);
  90.   OpenGfx;
  91.   font64.ta_Name := 'C64Umod.font';
  92.   font64.ta_YSize := 8;
  93.   font64.ta_Style := 0;
  94.   font64.ta_Flags := 0;
  95.   huh := OpenDiskFont(^font64);
  96.   newS.LeftEdge := 0;
  97.   newS.TopEdge := 0;
  98.   newS.Width := 320;
  99.   newS.Height := 200;
  100.   newS.Depth := 2;
  101.   newS.DetailPen := 1;
  102.   newS.BlockPen := 0;
  103.   newS.ViewModes := 0;
  104.   newS._Type := CUSTOMSCREEN;
  105.   newS.Font := ^font64;
  106.   newS.DefaultTitle := '15x1 Directory Display Screen';
  107.   ptrScr := OpenScreen(^newS);
  108.   ptrVP := ^ptrScr^.ViewPort;
  109.   ptrWin := Open_Window(0,
  110.                         0,
  111.                         320,
  112.                         200,
  113.                         0,
  114.                         1,
  115.                         0,
  116.                         SMART_REFRESH or ACTIVATE or BORDERLESS or BACKDROP,
  117.                         '15x1 Directory Display Window',
  118.                         ptrScr,
  119.                         0,
  120.                         0,
  121.                         320,
  122.                         200);
  123.   ptrRP := ptrWin^.RPort;
  124.   ptrMP := CreateMsgPort;
  125.   ptrIOR := CreateIORequest(ptrMP, sizeof(IOStdReq));
  126.   ptrIOR^.IO_DATA := ptrWin;
  127.   ptrIOR^.IO_LENGTH := 132;
  128.   status := OpenDevice('console.device', 0, ptrIOR, 0);
  129.   ShowTitle(ptrScr, {false}0);
  130.   SetAPen(ptrRP, 2);
  131.   SetBPen(ptrRP, 3);
  132.   SetRast(ptrRP, 3);
  133.   LoadRGB4(ptrVP, ^blues, 4);
  134.   for i := 0 to 3
  135.     do showLine(i);
  136.   ch := 'x';
  137.   while not ((ch = ' ') or (ch = '0') or (ch = '1'))
  138.     do ch := keybdRd;
  139.   if ch = '1'
  140.       then drive := 1
  141.     else drive := 0;
  142.   if ch = ' '
  143.       then begin
  144.         sep := '",'
  145.         lenSep := 2
  146.       end
  147.     else begin
  148.       sep := ch + '",';
  149.       lenSep := 3
  150.     end;
  151.   Move(ptrRP, 6 * 8, 6 * 8 + 7);
  152.   GrafxText(ptrRP, ^sep, lenSep);
  153.   ch := 'x';
  154.   while not ((ch = ' ') or (ch = '1') or (ch = '8') or (ch = '9'))
  155.     do ch := keybdRd;
  156.   if ch = ' '
  157.       then begin
  158.         sep := '8';
  159.         devyce := 8
  160.       end
  161.     else if ch = '1'
  162.              then begin
  163.                GrafxText(ptrRP, ^ch, 1);
  164.                ch := 'x';
  165.                while not ((ch = '0') or (ch = '1'))
  166.                  do ch := keybdRd;
  167.                sep := ch;
  168.                devyce := ord(ch) - 38 { ord('0') + 10 }
  169.              end
  170.     else begin
  171.       sep := ch;
  172.       devyce := ord(ch) - 48 { ord('0') }
  173.     end;
  174.   GrafxText(ptrRP, ^sep, 1);
  175.   OpenIEC;
  176.   { Ask for the directory (LOAD"$",device) }
  177.   Listen(devyce);
  178.   Second(CMD_OPEN + 0);
  179.   if IECBase^.iec_ST <> ST_OK
  180.       then writeln('Device number ', devyce, ' not responding!')
  181.     else begin
  182.       for i := 4 to 7
  183.         do showLine(i);
  184.       CIOut('$');
  185.       CIOut(chr(drive + 48));
  186.       UnListen;
  187.       { Start receiving data }
  188.       Talk(devyce);
  189.       TkSA(CMD_DATA + 0);
  190.       { Ignore load address }
  191.       ch := ACPtr;
  192.       ch := ACPtr;
  193.       done := false;
  194.       rowNo := 13 - 1;
  195.       while not done
  196.         do begin
  197.           ch := ACPtr;
  198.           done := IECBase^.iec_ST <> ST_OK;
  199.           if not done
  200.               then begin
  201.                 ch := ACPtr;
  202.                 done := IECBase^.iec_ST <> ST_OK
  203.               end;
  204.           if not done
  205.               then begin { get block count }
  206.                 low := ord(ACPtr);
  207.                 done := IECBase^.iec_ST <> ST_OK;
  208.                 if not done
  209.                     then begin
  210.                       high := ord(ACPtr);
  211.                       done := IECBase^.iec_ST <> ST_OK
  212.                     end;
  213.               end;
  214.           if not done
  215.               then begin { display count and name }
  216.                 if rowNo > 23
  217.                     then ScrollRaster(ptrRP, 0, 8, 0, 0, 319, 199)
  218.                   else rowNo := rowNo + 1;
  219.                 countStr := intstr(high shl 8 + low) + ' ';
  220.                 size := length(countStr);
  221.                 write(countStr);
  222.                 Move(ptrRP, 0, rowNo * 8 + {6}7);
  223.                 GrafxText(ptrRP, ^countStr, size);
  224.                 nameC := '';
  225.                 nameS := '';
  226.                 revVid := false;
  227.                 ch := ACPtr;
  228.                 while ch <> #$00
  229.                   do begin
  230.                     if ch = #$12
  231.                         then begin
  232.                           nameC := nameC + #$9B + '7m';
  233.                           revVid := true
  234.                         end
  235.                       else begin
  236.                         nameC := nameC + ch;
  237.                         nameS := nameS + ch
  238.                       end;
  239.                     ch := ACPtr
  240.                   end;
  241.                 if revVid
  242.                     then nameC := nameC + #$9B + '0m';
  243.                 writeln(nameC);
  244.                 Move(ptrRP, size * 8, rowNo * 8 + {6}7);
  245.                 if revVid
  246.                     then SetDrMd(ptrRP, 5);
  247.                 GrafxText(ptrRP, ^nameS, length(nameS));
  248.                 if revVid
  249.                     then SetDrMd(ptrRP, 1)
  250.               end { display count and name }
  251.         end;
  252.       UnTalk;
  253.       Listen(devyce);
  254.       Second(CMD_CLOSE + 0);
  255.       UnListen;
  256.       ch := keybdRd
  257.     end;
  258.   CloseDevice(ptrIOR);
  259.   DeleteIORequest(ptrIOR);
  260.   DeleteMsgPort(ptrMP);
  261.   Close_Window(ptrWin);
  262.   CloseScreen(ptrScr)
  263. end.
  264.